package com.gjx.clock.ui

import android.app.Activity
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Gravity
import android.view.WindowManager
import com.gjx.clock.R

class OnePxActivity : Activity() {
    companion object{
        val ACTION_FINISH_ACTIVITY = "ACTION_FINISH_ACTIVITY"
    }
    val receiver = object:BroadcastReceiver(){
        override fun onReceive(context: Context?, intent: Intent?) {
            this@OnePxActivity.finish()
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window.setGravity(Gravity.LEFT or Gravity.TOP)
        val params = window.attributes
        params.x=0
        params.y=0
        params.width=1
        params.height=1
        window.attributes=params
        registerReceiver(receiver, IntentFilter(ACTION_FINISH_ACTIVITY))
    }

    override fun onDestroy() {
        unregisterReceiver(receiver)
        super.onDestroy()
    }
}
